/*
 * @Author: 一路向阳 tt_sunzhenfeng@163.com
 * @Date: 2024-05-23 22:48:41
 * @LastEditors: 一路向阳 tt_sunzhenfeng@163.com
 * @LastEditTime: 2024-05-23 23:02:28
 * @FilePath: \vue3_nuxt_demo\server\api\note\index.get.ts
 * @Description: 获取所有文集列表接口
 */
import { responseJson } from '@/server/utils/helper';
import { getDB } from '@/server/utils/db';

export default defineEventHandler(
  async (event)=>{

    // 数据库交互
    const { find, close } = getDB();

    // 查询
    const con = find();

    try {

      //获取用户文集
      const [rows] = await con.execute('SELECT * FROM `notebooks`');

      return  responseJson(200,{
        success: true,
        msg: '获取成功',
        data: rows
      });
    }
    catch (error){

      setResponseStatus(event,500);
      return responseJson(500,{
        success: false,
        msg: '服务器错误',
        error: error
      });
    }
    finally {
      // 释放连接
      close();
    }
})